﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using PowerTools;
using System.Linq;
using System.IO;

namespace PowerTools_Test
{
    /// <summary>
    /// Summary description for XML
    /// </summary>
    [TestClass]
    public class XML
    {
        public XML()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion Additional test attributes

        [TestMethod]
        [DeploymentItem("Pouvoirs3_v1.0.10.xml")]
        public void LoadXML()
        {
            string pouvoirs3V1XML = "Pouvoirs3_v1.0.10.xml";
            Assert.IsTrue(File.Exists(pouvoirs3V1XML));
            PouvoirsXML xml = PouvoirsXML.LoadFromFile(pouvoirs3V1XML);
            Assert.IsFalse(string.IsNullOrWhiteSpace(xml.Titre),"titre manquant");
            // If title is empty, check that its attribute is XmlAttributeAttribute
            // and not  XMLElementAttribute
            Assert.IsTrue(xml.nombrepouvoir[0].valeur > 0);
       // si plantage :
            // There is an error in XML document (2, 2). ---> System.InvalidOperationException: <PouvoirsXML xmlns=''> was not expected.
            // mettre dans pouvoir.designer.cs     [XmlRoot( IsNullable = false, ElementName = "PouvoirsXML")] sur PouvoirsXML
            Assert.IsTrue(xml.Officiel,"Fichier officiel non détecté");
            PouvoirsXMLPouvoir p = xml.pouvoir[0];
            Assert.IsFalse(string.IsNullOrEmpty(p.livre),"Pas de livre pour " + p.nom);
        }

        [TestMethod]
        [DeploymentItem("Definitions.xml")]
        public void LoadXMLDef()
        {
            //PouvoirsXML.PouvoirsXML xml = PouvoirsXML.PouvoirsXML.LoadFromFile("Pouvoirs2_v1.0.9.xml");
            Definitions xml = Definitions.LoadFromFile("dEFINITIONS.xml");
            //XMLFichierPouvoirs xml = XMLFichierPouvoirs.LoadFromFile("Pouvoirs2_v1.0.9.xml");
            Assert.IsTrue(xml.livres.Count > 0);

        }
    }
}